package com.neulogistics.contrib.procuredcenter.infrastructure.persistence.repository;

import com.neulogistics.contrib.procuredcenter.domain.model.aggregate.GoodsList;
import com.neulogistics.contrib.procuredcenter.domain.repository.IGoodsListRepository;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.converter.GoodsListEntityPOConverter;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.po.GoodsListPO;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.service.IGoodsListPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class GoodsListRepository implements IGoodsListRepository {
    @Resource
    IGoodsListPOService goodsListPOService;

    @Override
    public void save(GoodsList goodsList) {
        GoodsListPO goodsListPO = GoodsListEntityPOConverter.entityToPO(goodsList);
        goodsListPOService.saveOrUpdate(goodsListPO);
        goodsList.setListId(goodsListPO.getListId());
    }

    @Override
    public GoodsList findById(Integer id) {
        GoodsListPO goodsListPO = goodsListPOService.getById(id);
        GoodsList goodsList = GoodsListEntityPOConverter.POToEntity(goodsListPO);
        return goodsList;
    }

    @Override
    public void deleteById(Integer id) {
        goodsListPOService.removeById(id);
    }
}
